﻿/*
Copyright © 2011 François Karman

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

See <license.txt> for the complete license of the software.
*/

using System;

namespace Simple.Storage
{
    /// <summary>
    /// Provides details about how to manipulate a property.
    /// </summary>
    /// <remarks>
    /// The implementations of this interface should be immutable to avoid any side effect.
    /// </remarks>
    public interface IPropertyDefinition
    {
        /// <summary>
        /// Gets the type of the property.
        /// </summary>
        Type Type { get; }

        /// <summary>
        /// Gets a value indicating whether the a in-place serialization should
        /// be used for this property (no use of the <see cref="IPropertyDefinition.SetValue"/>).
        /// </summary>
        bool RequireInPlace { get; }

        /// <summary>
        /// Extracts the value of the property from a specific object.
        /// </summary>
        /// <param name="instance">The instance of the parent object.</param>
        /// <returns>
        /// The value of the property in <paramref name="instance"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="instance"/> parameter is <c>null</c>.
        /// </exception>
        object GetValue(object instance);

        /// <summary>
        /// Defines the value of the property for a specific object.
        /// </summary>
        /// <param name="instance">The instance of the parent object.</param>
        /// <param name="value">The new value for the property.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="instance"/> parameter is <c>null</c>.
        /// </exception>
        void SetValue(object instance, object value);
    }
}
